/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.dusin.task;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * Web application lifecycle listener.
 * 已弃用
 * @author tengyu
 */
public class ApplicationListener implements ServletContextListener {
    
    private TaskThread taskThread;

    public void contextInitialized(ServletContextEvent sce) {
        String str = null;  
        if (str == null && taskThread == null) {  
            taskThread = new TaskThread();  
            taskThread.setServletContext(sce.getServletContext());
            taskThread.start(); // servlet 上下文初始化时启动 socket  
            //System.out.println("$$$$$$$$$$$$$$启动线程"+taskThread.getName());
        }        
    }

    public void contextDestroyed(ServletContextEvent sce) {
        //System.out.println("$$$$$$$$$$$$进入destoryed");
        if (taskThread != null && taskThread.isAlive()) {  
            //System.out.println("$$$$$$$$$$$$$$$$结束线程"+taskThread.getName());
            taskThread.makeItStop();            
        }
    }
}
